package com.xingkeduo.config;

import com.xingkeduo.dto.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * <p>
 * 全局异常处理配置
 */

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 全局业务异常
     *
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public ResponseEntity errorHandler(Exception ex) {
        log.info("Exception:{}", ex);
        return new ResponseEntity<>(ResponseUtils.error(ex.getMessage(), ""), HttpStatus.OK);
    }
}
